/*
Copyright 2010-2011 CumulusCloud
http://cumuluscloud.cc

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cumulusCloud.common;

import javax.servlet.http.HttpServletRequest;

import cumulusCloud.common.objects.CloudUser;
import cumulusCloud.knowledge.SessionKnow;

/**
 * This class gives information and can modify the cloud session
 * 
 * @author Simon Levesque
 *
 */
public class ManageSession {
	static private SessionKnow know = SessionKnow.getInstance();
	
	/**
	 * To create a session for a user. The credential needs to be valid
	 * 
	 * @param user The username
	 * @param password The password of that user
	 * @return The session token or null if the credential is invalid
	 */
	public static String createSession(String user, String password) {
		return know.createSession(user, password);
	}
	
	/**
	 * To delete a session (logout)
	 * 
	 * @param userToken The session token to delete
	 */
	public static void deleteSession(String userToken) {
		know.deleteSession(userToken);
	}
	
	/**
	 * To get the session associated with that request
	 * 
	 * @param request The current request
	 * @return The session token
	 */
	public static String getCurrentUserToken(HttpServletRequest request) {
		return know.getCurrentUserToken(request);
	}
	
	/**
	 * To get the user's information
	 * 
	 * @param userToken The current session token associated with that user
	 * @return The user
	 */
	public static CloudUser getSessionUser(String userToken) {
		return know.getSessionUser(userToken);
	}
	
}
